home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_44917.txt < prev    next >
Text File  |  1991-02-27  |  1KB  |  31 lines

  1. -- card: 44917 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 6
  9. ----- text -----
  10. 5.3  Type Conversion
  11.  
  12. -- part contents for background part 4
  13. ----- text -----
  14. AUTOMATIC TYPE CONVERSION
  15.  
  16. C attempts to preserve the value of an expression when mixed with an expression or variable of another type.  As was seen in Chapter 2, chars are automatically converted to ints in mixed arithmetic expressions.  During arithmetic involving both ints and doubles, ints are "promoted" to double, as are floats when mixed with doubles.
  17.  
  18. In fact, previous to ANSI C, all expressions involving floats were converted to double. ANSI C allows single-precision arithmetic operations when all operands are float; however, this is one feature of ANSI C which is NOT presently supported by TC.
  19.  
  20. When an assignment operator is used, the value of the right side is converted to the type of the left side where possible.  High-order bits in an int are discarded when converted to char, if necessary.  The fractional part of a float is discarded when converted to int.  A double is rounded when converting to float.
  21.  
  22. As discussed later in this section, values may be explicitly converted to another type by the programmer, to supercede the automatic type conversion rules.  In fact, 
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. -- part contents for background part 7
  30. ----- text -----
  31. 147